export class GameDataManager {
    private static instance: GameDataManager;
    public static get Instance(): GameDataManager {
        if (!this.instance) {
            this.instance = new GameDataManager;
            this.instance.Init();
        }
        return this.instance;
    }

    private Init() {
        // localStorage.clear();
        let array = ["Tutorial", "Coin", "Diamond", "Daily"];
        for (let i = 0; i < array.length; i++) {
            const element = array[i];
            if (localStorage.getItem("PUBG_" + element) == null || localStorage.getItem("PUBG_" + element) == "") localStorage.setItem("PUBG_" + element, (element == "Wing" || element == "Head") ? "4" : "0");
        }
        let array2 = ["AllSkin", "Weapon", "LastDaily", "SkinPieces", "LastLogin", "Tasks", "TaskRequires", "UseSkin"];
        for (let i = 0; i < array2.length; i++) {
            const element = array2[i];
            if (localStorage.getItem("PUBG_" + element) == null || localStorage.getItem("PUBG_" + element) == "") localStorage.setItem("PUBG_" + element, JSON.stringify(element == "AllSkin" ? [[1, 0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] : element == "Weapon" ? [1, 0] : element == "SkinPieces" ? [[20, 0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] : (element == "Tasks" || element == "TaskRequires") ? [0, 0, 0] : element == "UseSkin" ? [0, -1, -1, -1] : []));
        }
        let array3 = [];
        for (let i = 0; i < array3.length; i++) {
            const element = array3[i];
            if (localStorage.getItem("PUBG_" + element) == null || localStorage.getItem("PUBG_" + element) == "") localStorage.setItem("PUBG_" + element, JSON.stringify({}));
        }
    }

    public getNumberData(str: string): number {
        let data = localStorage.getItem("PUBG_" + str);
        return parseInt(data);
    }

    public setNumberData(str: string, value: number) {
        localStorage.setItem("PUBG_" + str, value.toString());
    }

    public getArrayData<T = number>(str: string): T[] {
        let data = localStorage.getItem("PUBG_" + str);
        return JSON.parse(data);
    }

    public setArrayData<T>(str: string, value: T[]) {
        localStorage.setItem("PUBG_" + str, JSON.stringify(value));
    }

    public getRecordData(str: string) {
        let data = localStorage.getItem("PUBG_" + str);
        return JSON.parse(data);
    }

    public setRecordData(str: string, value: any) {
        localStorage.setItem("PUBG_" + str, JSON.stringify(value));
    }
}


